<!-- 项目附件 -->
<template>
    <u-collapse-item @change="handleChange" ref="initcollapse" :open="true">
        <uni-view slot="title" class="u-page__title">项目附件信息</uni-view>
        <!-- 附件列表信息 -->
        <view ref="getcontenier" class="conterier-page" >
          <view v-if="fileList.length>0">
            <view v-if="showPrjStatge">
              <view v-for="(_item, _index) in PrjStateType" :key="_item.key">
                <uni-view class="prjStage-content" v-if="jieduanContent(_item)">
                  <uni-view style="color: #000000;font-size: 32rpx;"> {{ _item.value
                    }}</uni-view>
                  <view class="show-icon" @click="changeIconContent(_index)">
                    <u-icon v-if="_item.expantedShow" name="arrow-up" color="#909399" size="28"></u-icon>
                    <u-icon v-else name="arrow-down" color="#909399" size="28"></u-icon>
                  </view>
                </uni-view>
                <!-- 项目一级列表 -->
                <view v-if="_item.expantedShow">
                  <view class="page" v-for="(item, index) in fileList" :key="index">
                    <view :class="['outside']" v-if="_item.key===item.prjStage">
                      <uni-view class="donwond-title" @click="initLoad(item)">{{
                          item.fileName }}</uni-view>
                      <button
                          style="border: none;outline: none;height: 52rpx;line-height: 47rpx;border-radius: 50rpx;color: #fff;background: #ca171d;font-size:32rpx;"
                          plain="true" @click="item.showTypes?handelPop(item):initLoad(item)">{{ item.showTypes?'操作':'下载' }}</button>
                      <view class="show-icon" @click="changeIcon(index)">
                        <u-icon v-if="item.expanted" name="arrow-up" color="#909399" size="28"></u-icon>
                        <u-icon v-else name="arrow-down" color="#909399" size="28"></u-icon>
                      </view>
                    </view>
                    <!-- 展开的内容 -->
                    <view v-if="item.expanted" :class="['file-list', _index % 2 ? 'add-color' : '']"
                          v-for="(_item, _index) in fileListLabel" :key="_index">
                      <uni-view style="color: #000000;font-size: 32rpx"> {{ _item.label }}</uni-view>
                      <uni-view style="width: 70%;text-align: right;color: #666666;font-size: 28rpx;word-break: break-word;">{{
                          _item.prop !== 'isSignature' ?
                              showContent(_item.prop, item[_item.prop], item) :
                              enumObj[item[_item.prop]] }}</uni-view>
                    </view>
                  </view>
                </view>
              </view>
            </view>
            <view v-else>
              <!-- 项目一级列表 -->
              <view class="page" v-for="(item, index) in fileList" :key="index">
                <view :class="['outside']">
                  <uni-view class="donwond-title" @click="initLoad(item)">{{
                      item.fileName }}</uni-view>
                  <button
                      style="border: none;outline: none;height: 52rpx;line-height: 47rpx;border-radius: 50rpx;color: #fff;background: #ca171d;font-size:32rpx;"
                      plain="true" @click="item.showTypes?handelPop(item):initLoad(item)">{{ item.showTypes?'操作':'下载' }}</button>
                  <view class="show-icon" @click="changeIcon(index)">
                    <u-icon v-if="item.expanted" name="arrow-up" color="#909399" size="28"></u-icon>
                    <u-icon v-else name="arrow-down" color="#909399" size="28"></u-icon>
                  </view>
                </view>
                <!-- 展开的内容 -->
                <view v-if="item.expanted" :class="['file-list', _index % 2 ? 'add-color' : '']"
                      v-for="(_item, _index) in fileListLabel" :key="_index">
                  <uni-view style="color: #000000;font-size: 32rpx"> {{ _item.label }}</uni-view>
                  <uni-view style="width: 70%;text-align: right;color: #666666;font-size: 28rpx;word-break: break-word;">{{
                      _item.prop !== 'isSignature' ?
                          showContent(_item.prop, item[_item.prop], item) :
                          enumObj[item[_item.prop]] }}</uni-view>
                </view>
              </view>
            </view>
          </view>
          <view v-if="fileList.length===0&&!isShows(this.params.type)" style="text-align: center;height: 130rpx;line-height: 130rpx;">暂无数据</view>
            <!-- 上传文件按钮 -->
            <view class="add-file" @click="addFile" v-if="isShows(this.params.type)">
                <u-icon name="plus" color="#909399" size="36"></u-icon>
            </view>
            <!-- 删除/下载 -->
            <u-popup ref="dialogConfirmRef" v-model="show" mode="bottom" zIndex="10001" @close="close">
                <view
                    style="margin:20rpx;flex-wrap: wrap;font-size: 30rpx;display: flex;justify-content:space-evenly;align-items: center;">
                    <!-- <view v-if="isShows(this.params.type)"
                        style="width: 25%;display: flex;flex-direction:column;align-items: center;" @click="Edits">
                        <image style="width: 80rpx;height: 80rpx;" src="@/static/imges/attachment/bianji_.png" mode="">
                        </image>
                        <text style="font-size: 32rpx;color: #333;">编辑</text>
                    </view> -->
                    <view style="width: 25%;display: flex;flex-direction:column;align-items: center;"
                        @click="dowonload">
                        <image style="width: 80rpx;height: 80rpx;" src="@/static/imges/attachment/xiazai.png" mode="">
                        </image>
                        <text style="font-size: 32rpx;color: #333;">下载</text>
                    </view>
                    <view v-if="isShows(this.params.type)"
                        style="width: 25%;display: flex;flex-direction:column;align-items: center;" @click="deleteFile">
                        <image style="width: 80rpx;height: 80rpx;" src="@/static/imges/attachment/shanchu.png" mode="">
                        </image>
                        <text style="font-size: 32rpx;color: #333;">删除</text>
                    </view>
                </view>
            </u-popup>
            <!-- 删除弹框 -->
            <view ref="modelRef"
                style="width: 100vw;height: 100vh;background: rgba(58, 58, 58, 0.5);position: fixed;top: 0;left: 0;display: flex;align-items: center;justify-content: center"
                v-if="delShow">
                <view style="background: #FFFFFF;width: 80%;border-radius: 10rpx;width: 580rpx;height: 330rpx;">
                    <view
                        style="font-size: 36rpx;font-weight: bold;text-align: center;margin-top: 40rpx;margin-bottom: 20rpx;color:rgb(49, 49, 49)">
                        温馨提示</view>
                    <view style="font-size: 30rpx;;text-align: center;color: rgb(153, 153, 153,0.6);">请确认删除所选数据, 是否继续?
                    </view>
                    <view style="margin-top:50rpx;display: flex;color: #fff;justify-content: center;">
                        <view
                            style="margin-right: 30rpx;;text-align: center;width: 180rpx; height: 60rpx; line-height: 60rpx; font-size: 30rpx;border-radius: 30rpx;background: #FFFFFF;color: #CA171D;border:2rpx solid #CA171D;"
                            @click.stop="cancelDel()">取消</view>
                        <view type="warn"
                            style="text-align: center;width: 180rpx; height: 60rpx; line-height: 60rpx; font-size: 30rpx;border-radius: 30rpx;background: #CA171D;"
                            @click.stop="confirmDel()">确定</view>
                    </view>
                </view>
            </view>
            <view ref="modelRefMessage"
                style="width: 100vw;height: 100vh;background: rgba(58, 58, 58, 0.5);position: fixed;top: 0;left: 0;display: flex;align-items: center;justify-content: center"
                v-if="messageShow">
                <view style="background: #FFFFFF;width: 80%;border-radius: 10rpx;width: 580rpx;">
                    <view
                        style="font-size: 36rpx;font-weight: bold;text-align: center;margin-top: 40rpx;margin-bottom: 20rpx;color:rgb(49, 49, 49)">
                        温馨提示</view>
                    <view style="font-size: 30rpx;;text-align: center;color: rgb(153, 153, 153,0.6);padding: 0 20rpx;">
                        {{ messafeInfo }}</view>
                    <view
                        style="margin-top:50rpx;display: flex;color: #fff;justify-content: center;margin-bottom: 50rpx;">
                        <view type="warn"
                            style="text-align: center;width: 180rpx; height: 60rpx; line-height: 60rpx; font-size: 30rpx;border-radius: 30rpx;background: #CA171D;"
                            @click.stop="() => { messageShow = !messageShow }">确定</view>
                    </view>
                </view>
            </view>
            <!-- 上传文件弹框 -->
            <u-popup ref="dialogConfirmRef" v-model="fileShow" mode="bottom">
                <view style="padding:20rpx 40rpx 0rpx 40rpx;height: 600rpx;" v-if="!showIcon">
                    <view style="position: relative;">
                        <view style="display: flex;align-items: center;justify-content: space-between">
                            <label class="common-list-title-ex" style="margin-right: 6rpx;">文件类型 :</label>
                            <uni-data-select v-model="valueSelect" :localdata="typeList" @change="closeSelect($event)"
                                :emptyTips="'暂无数据'" placeholder="请选择文件类型"></uni-data-select>
                        </view>
                    </view>
                    <!-- 上传文件/相机/相册 -->
                    <view style="display: flex;justify-content: space-between;">
                        <view style="margin: 20rpx 0;display: flex;justify-content: space-between;"
                            v-for="(btn, index) in btnListOption" :key="index">
                            <view @click="handleBtnClick(btn.method)"
                                style="display: flex;flex-direction: column;align-items: center;">
                                <image style="width: 80rpx;height: 80rpx;" :src="btn.url" mode=""></image>
                                <text style="font-size: 32rpx;color: #333;width: 160rpx;text-align: center;">{{
                                    btn.title }}</text>
                            </view>
                        </view>
                    </view>
                </view>
            </u-popup>
        </view>
    </u-collapse-item>
</template>

<script>
// 列表配置文件
const fileListLabelA = [
    {
        label: "分项",
        prop: "fenxiang"
    },
    {
        label: "文件类型",
        prop: "docTypeName"
    },
    {
        label: "文件上传人",
        prop: "uploaderName"
    },
    {
        label: "单位",
        prop: "orgName"
    },
    {
        label: "文件获取方式",
        prop: "fileSource"
    },
    {
        label: "文件获取时间",
        prop: "uploadTime"
    },
    {
        label: "是/否电子签章",
        prop: "isSignature"
    },
    {
        label: "文件名称",
        prop: "fileName"
    },

    {
        label: "签署状态",
        prop: "signatureStatus"
    },
    // {
    //     label: "是/否审计必审",
    //     prop: "isAudit"
    // }
]
// 列表配置文件
const fileListLabelB = [
    {
        label: "分项",
        prop: "fenxiang"
    },
    {
        label: "文件类型",
        prop: "docTypeName"
    },
    {
        label: "文件上传人",
        prop: "uploaderName"
    },
    {
        label: "文件获取方式",
        prop: "fileSource"
    },
    {
        label: "文件获取时间",
        prop: "uploadTime"
    },
    {
        label: "文件名称",
        prop: "fileName"
    },
]
import CryptoJS from "crypto-js";
export default {
    name: "ZrAttachMent",
    props: {
        // 参数
        attachMentObj: {
            type: Object,
            default: () => ({
                // sysToken: 'c64dd4dac160904f76a09c81b078228a',
                // prjStage: 'Q',
                // prjId: '9297033',
                // nodeId: 'ss01_shi',
                // prjType: 'M',
                // roomType: '0',
                // towerType: '0',
                // buildModes: '01',
                // activityId: 'sett_01',
                // isChange: '0',
                // type: 'todo'
            })
        },
        showPrjStatge: {
            type: Boolean,
            default: false
        },
        showSign:{
            type: Boolean,
            default: true
        }
    },
    data() {
        return {
            formationShow: true,
            errorTitle: "",
            delShow: false,
            enumObj: {
                '0': '否',
                '1': '是'
            },
            fileShow: false,//上传文件之前弹框
            show: false,
            showIcon: false,// 是否展开
            fileListLabel:[],// 列表配置文件
            PrjStateType: [
                {
                    "key": "B",
                    "value": "立项阶段",
                    expantedShow: false
                },
                {
                    "key": "K",
                    "value": "采购阶段",
                    expantedShow: false
                },
                {
                    "key": "E",
                    "value": "实施阶段",
                    expantedShow: false
                },
                {
                    "key": "F",
                    "value": "验收阶段",
                    expantedShow: false
                },
                {
                    "key": "G",
                    "value": "决算阶段",
                    expantedShow: false
                },
                {
                    "key": "J",
                    "value": "设计变更阶段",
                    expantedShow: false
                },
                {
                    "key": "H",
                    "value": "销项阶段",
                    expantedShow: false
                },
                {
                    "key": "HQ",
                    "value": "会签阶段",
                    expantedShow: false
                },
                {
                    "key": "WE",
                    "value": "质量监控阶段",
                    expantedShow: false
                },
                {
                    "key": "D",
                    "value": "设计阶段",
                    expantedShow: false
                },
                {
                    "key": "WB",
                    "value": "设计监理标识变更阶段",
                    expantedShow: false
                },
                {
                    "key": "AM",
                    "value": "特别修正阶段",
                    expantedShow: false
                },
                {
                    "key": "WZ",
                    "value": "其它阶段",
                    expantedShow: false
                },
                {
                    "key": "WC",
                    "value": "设计监理工作量阶段",
                    expantedShow: false
                },
                {
                    "key": "C",
                    "value": "可研阶段",
                    expantedShow: false
                },
                {
                    "key": "ZJ",
                    "value": "作业计划审核阶段",
                    expantedShow: false
                },
                {
                    "key": "Q1",
                    "value": "服务商调整确认阶段",
                    expantedShow: false
                },
                
                {
                    "key": "WD",
                    "value": "电子签章阶段",
                    expantedShow: false
                },
                
                {
                    "key": "BD",
                    "value": "立项/设计阶段",
                    expantedShow: false
                },
                {
                    "key": "O",
                    "value": "项目关闭阶段",
                    expantedShow: false
                },
                {
                    "key": "FD",
                    "value": "外电设计监理费阶段",
                    expantedShow: false
                },
                {
                    "key": "Q",
                    "value": "结算阶段",
                    expantedShow: false
                },
                {
                    "key": "ZR",
                    "value": "作业人员审核阶段",
                    expantedShow: false
                },
                
                {
                    "key": "IN",
                    "value": "IT验工计价阶段",
                    expantedShow: false
                }],//阶段配置文件
            // 文件列表
            fileList: [
            ],
            // 删除/下载文件的对象
            commenObj: {

            },
            params: {

            },
            // 选中的文件类型
            form: {
                type: ""
            },
            typeList: [

            ],
            // 生成文件类型保存
            saveTypeData: [],
            typeArray: [],//允许上传的文件类型
            productTypeObj: {
                PRO_STAGE: [],
                FILE_UPLOAD_MODES: [
                    {
                        value: '手动上传',
                        key: '0'
                    },
                    {
                        value: '系统生成',
                        key: '1'
                    },
                    {
                        value: '系统生成/手动编辑',
                        key: '2'
                    }
                ],
                SIGN_STATE2: []
            },
            // 按钮
            btnListOption: [
                {
                    method: 'upLoadImage',
                    title: '上传图片',
                    url: require('@/static/imges/attachment/tupian.png')
                },
                {
                    method: 'upLoadFile',
                    title: '上传文件',
                    url: require('@/static/imges/attachment/shangchuan.png')
                },
                {
                    method: 'cameraFile',
                    title: '相机',
                    url: require('@/static/imges/attachment/zhaoxiangji.png')
                },
            ],
            messafeInfo: "",
            messageShow: false,
            valueSelect: '',
        };
    },
    mounted() {
        this.params = this.attachMentObj
        uni.setStorageSync("sysToken", this.params.sysToken)
        console.log(this.params, "附件页面初始化props接收参数=>");
        if(this.showSign){
            this.fileListLabel = JSON.parse(JSON.stringify(fileListLabelA))
        }else{
            this.fileListLabel = JSON.parse(JSON.stringify(fileListLabelB))
        }
        // 设置token
        this.getInitFileList()
        this.getPrjStage()
        this.queryFileWhitelist()
    },
    methods: {
        jieduanContent(row) {
            let _list = this.fileList.filter(item => item.prjStage === row.key)
            return _list.length > 0
        },
        dialogBody(refName, _this) {
            const contentBody = window.top.document.body
            _this.$nextTick(() => {
                const elBody = _this.$refs[refName].$el
                elBody.style.zIndex = 10076
                contentBody.appendChild(elBody)
            })
        },
        handleBtnClick(fun) {
            this[fun]()
        },
        showContent(_item, value, row) {
            // if (item === 'prjStage') {
            //     let lists = this.productTypeObj.PRO_STAGE.filter(item => item.key === value)
            //     return lists[0]?.value
            // } 
            if (_item === 'fileSource') {
                let listsTwo = this.productTypeObj.FILE_UPLOAD_MODES.filter(item => item.key === value)
                return listsTwo[0]?.value
            } else if (_item === 'signatureStatus') {
                let listsThree = this.productTypeObj.SIGN_STATE2.filter(item => item.dictId === value)
                return listsThree[0]?.dictName ? listsThree[0]?.dictName : '-'
            } else if (_item === 'fenxiang') {
                let lists = this.productTypeObj.PRO_STAGE.filter(item => item.key === row.prjStage)
                return lists[0]?.value + ' : ' + row.nodeName
            } else {
                return value
            }
        },
        // 获取项目阶段字典
        async getPrjStage() {
            let res1 = this.$axios.get('/attachment/api/attachment/file/getPrjStage')
            let res2 = this.$axios.get('/material/api/sys/dict/getDictData', { dictTypeId: 'SIGN_STATE2' })
            const results = await Promise.all([res1, res2])
            if (+results[0].code === 200 && +results[1].code === 200) {
                this.PrjStateType = results[0].data.map(item=>{
                    return {
                        ...item,
                        expantedShow:false
                    }
                })
                this.productTypeObj.PRO_STAGE = results[0]?.data
                this.productTypeObj.SIGN_STATE2 = results[1]?.data
            }
        },
        // 针对文档信息
        openPop() {
            this.formationShow = !this.formationShow
        },
        isShows(types) {
            return types === 'todo'
        },
        showErrorMessage(message) {
            this.messageShow = true
            this.messafeInfo = message
            this.dialogBody('modelRefMessage', this)
        },
        close() {
            this.show = false
        },
        Edits() {
            let row = [this.commenObj]
            if (['0', '1'].includes(row[0].fileSource)) {
                return this.showErrorMessage('仅支持对文件获取方式为“系统生成/手动编辑”进行编辑')
            }
            // 实施阶段跳降门页面，其余阶段暂时不跳
            if (this.params.prjStage !== 'E') {
                return this.showErrorMessage('当前附件非需编辑的电子化文档，请选择其他附件')
            }
        },
        decrypt(encryptedText,saltIv) {
            const key = CryptoJS.enc.Base64.parse('Q0hJTkFUT1dFUkNPTVBNUw=='); // 16字节的密钥
            const iv = CryptoJS.enc.Base64.parse(saltIv); // 16字节的初始化向量
            const decrypted = CryptoJS.AES.decrypt(encryptedText, key, {
                iv: iv,
                mode: CryptoJS.mode.CBC,
                padding: CryptoJS.pad.Pkcs7
            });
            return decrypted.toString(CryptoJS.enc.Utf8);
        },
        async dowonload() {
            if (!this.commenObj.filePath) {
                return this.showErrorMessage("下载失败")
            }
            // 后端加密地址
            const decryptedValue = this.decrypt(this.commenObj.filePath,this.commenObj.iv);
            console.log("解密: " + decryptedValue);
            let url = ""// 下载资源的 url
            // 二进制流1.0
            if (+this.commenObj.signs === 1) {
                url = uni.getStorageSync('urlDownload') + `/attachment/api/attachment/file/appDownloadFile?filePath=${decryptedValue}`
            } else {
                url = decryptedValue
                // let fileUrl = this.commenObj.filePath + this.commenObj.forntFilePath
                // 调2.0接口 拿到返回的url 进行端口映射替换
                // url = this.checkIpStartsWith(this.commenObj.filePath) ? this.changeHostPort(fileUrl) : fileUrl
            }
            console.log("准备下载", url);
            imp.iFile.download({ url: url, saveName: this.commenObj.fileName, autoOpen: true },
                function (data) {
                    if (data.status == 1) {
                        console.log("下载成功", data);
                    } else {
                        console.log("下载失败", data.error);
                    }
                })
        },
        // 是否是120.52开头的
        checkIpStartsWith(url) {
            // 使用正则表达式从URL中提取IP地址
            const ipRegex = /(\d{1,3}\.){3}\d{1,3}/;
            const match = url.match(ipRegex);

            if (match && match.length > 0) {
                const ip = match[0];
                // 检查IP地址是否以"120.52"开头
                return ip.startsWith('120.52');
            }

            // 如果没有找到IP地址，返回false或根据需要处理
            return false;
        },
        // 转为端口号
        changeHostPort(url) {
            let obj = {
                "120.52.40.57:15336": "192.168.53.243:7356",
                "120.52.40.57:15310": "192.168.53.42:8762",
                "120.52.40.57:15309": "192.168.53.41:8762",
                "120.52.40.57:15308": "192.168.53.40:8762",
                "120.52.40.57:15307": "192.168.53.39:8762",
                "120.52.40.57:15306": "192.168.53.38:8762",
                "120.52.40.57:15305": "192.168.53.37:8762",
                "120.52.40.57:15304": "192.168.53.37:8761",
                "120.52.40.57:15335": "192.168.53.39:8761",
                "120.52.40.57:15334": "192.168.53.38:8761"
            }
            // 提取原始URL中的host部分
            const hostRegex = /^https?:\/\/([^\/]+)/;
            const match = url.match(hostRegex);
            if (!match) {return url}; // 如果没有找到host部分，则返回原始URL

            const originalHost = match[1];

            // 在映射对象中找到对应的替换host
            const mappedHost = obj[originalHost];
            if (!mappedHost) {return url}; // 如果没有找到映射，则返回原始URL

            // 替换URL中的host部分
            return url.replace(originalHost, mappedHost);
        },
        commenTitle(titles) {
            // 关闭下载 删除编辑弹框
            this.close()
            this.showErrorMessage(titles)
        },
        // 删除文件
        deleteFile() {
            let row = [this.commenObj]
            console.log(row);
            const isDel = row.some(item => item.isSignature !== '1' || ['3', '4', '5', '9'].includes(item.signatureStatus))
            if (!isDel) {
                this.commenTitle('文件为电子签章时，仅支持签署状态为拒签、作废、已签署完成、转换失败时才能删除')
                return
            }
            const isRel = row.some(item => item.fileSource !== '0')
            if (isRel) {
                this.commenTitle('仅支持文件获取方式为手动上传的文件')
                return
            }
            const isRemove = row.some(item => item.nodeId !== row[0].nodeId)
            if (isRemove) {
                this.commenTitle('不同节点不支持批量删除')
                return
            }
            // 打开弹窗
            this.delShow = true
            this.dialogBody('modelRef', this)

        },
        // 取消删除
        cancelDel() {
            this.delShow = false
        },
        // 二次确认删除
        async confirmDel() {
            // 关闭下载 删除编辑弹框
            this.close()
            // 关闭删除弹框
            this.cancelDel()
            let row = [this.commenObj]
            const fileIdList = row.map(item => item.fileId)
            const params = {
                fileId: fileIdList.join(),
                supplementType: '',
                prjId:this.commenObj?.prjId
            }
            const { code, message } = await this.$axios.post('/attachment/api/attachment/file/batchDelete', [params])
            if (+code === 200) {
                this.getInitFileList()
                this.showErrorMessage(message)
            } else {
                this.showErrorMessage(message)
            }
        },
        handelPop(item) {
            this.commenObj = item
            this.show = true
            this.dialogBody('dialogConfirmRef', this)
        },
        // 标题下载
        initLoad(item) {
            this.commenObj = item
            this.dowonload()
        },
        // 切换是否展开下载文件信息
        changeIcon(index) {
            this.fileList[index].expanted = !this.fileList[index].expanted
            this.handleChange()
        },
        changeIconContent(index) {
            this.PrjStateType[index].expantedShow = !this.PrjStateType[index].expantedShow
            this.handleChange()
        },
        // 初始化获取文件列表
        async getInitFileList(doQuerParams) {
            const { prjStage, prjId } = this.params
            // 接口数据
            const paramObj = {
                pageNum: 1,
                pageSize: 9999,
                prjStage: prjStage,
                prjId: prjId,
                ...doQuerParams
            }
            const { code, data, message } = await this.$axios.post('/attachment/api/attachment/file/getPrjFileInfo', paramObj,)
            if (+code === 200) {
                const { records } = data
                this.fileList = records.map(item => {
                    return {
                        ...item,
                        expanted: false,
                        showTypes:this.params.type==='todo'
                    }
                })
            } else {
                this.showErrorMessage(message)
            }
            this.handleChange()
        },
        // 打开上传的弹框
        addFile() {
            this.valueSelect = ''
            this.fileShow = true
            this.form.type = ""
            this.showIcon = false
            this.getFileType()
            // dialogBody('dialogConfirmRef', this)
        },
        // 上传图片
        //调用MOA相册
        upLoadImage() {
            if (!this.form.type) {
                this.showErrorMessage('请先选择文件类型')
                return
            }
            uni.chooseImage({
                count: 1,
                sizeType: ['original', 'compressed'],
                sourceType: ['album'], //这要注意，camera掉拍照，album是打开手机相册
                success: (res) => {
                    if (!this.isShouldUpload(res, true)) {
                        return
                    }
                    const tempFilePaths = res.tempFiles
                    this.uploadFileImg(tempFilePaths[0], 'file')
                }
            });
        },
        //将相机、相册图片进行上传
        uploadFileImg(url, type) {
            uni.showLoading({
                title: '加载中...',
                mask: true
            });
            const { prjStage, prjId, activityId, isChange } = this.params
            const paramsObj = {
                file: url, // 文件
                docFileType: this.form.typeCode, // 文件类型
                prjId: prjId,
                activityId: activityId, // 流程id
                prjStage: prjStage, // 项目阶段
                isChange: isChange, // 上传方式 0:正常上传的,1:整改的,2:继承的
                operateSystem: 0,
                operateType: 1
            }
            console.log("准备上传的文件", paramsObj);
            let finishUrl = this.params.prjType==='M'?'/attachment/api/attachment/file/batchUpload':'/attachment/api/attachment/file/txBatchUpload'
            console.log("接口名称", finishUrl);
            uni.uploadFile({
                url: process.uniEnv.commonPMS20 + finishUrl,
                name: 'file',
                formData: paramsObj,
                header: {
                    'sysToken': uni.getStorageSync("sysToken"),
                },
                success: (res) => {

                    let { code, message } = JSON.parse(res.data)
                    if (+code === 200) {
                        uni.hideLoading();
                        this.showErrorMessage("上传成功")
                        this.fileShow = false
                        this.getInitFileList()
                    } else {
                        uni.hideLoading();
                        this.showErrorMessage(message)
                    }
                }
            });
        },
        // 上传文件
        upLoadFile() {
            if (!this.form.type) {
                this.showErrorMessage('请先选择文件类型')
                return
            }
            // 调用 uni-app 的 API 选择文件
            uni.chooseFile({
                count: 1,
                type: 'file',
                success: (res) => {
                    if (!this.isShouldUpload(res)) {
                        return
                    }
                    // 文件
                    const tempFilePaths = res.tempFiles
                    this.uploadFileImg(tempFilePaths[0], 'file')
                },
                fail: (error) => {
                    console.log(error)
                }
            })
        },
        // 获取上传文件的文件类型
        async getFileType() {
            const { buildModes, nodeId, prjStage, prjType, roomType, towerType,orgId } = this.params
            //文件类型 需要的参数
            let paramsFileType = {
                buildModes: buildModes,
                nodeId: nodeId,
                prjStage: prjStage,
                prjType: prjType,
                roomType: roomType ? roomType : 0,
                towerType: towerType ? towerType : 0,
                orgId:orgId
            }
            const res = await this.$axios.post('/attachment/api/attachment/file/getPrjFileType', paramsFileType,)
            if (+res.code === 200) {
                this.saveTypeData = res.data
                this.typeList = res.data.map(item => {
                    return {
                        value: item.typeCode,
                        text: item.typeName,
                    }
                })
            } else {
                this.showErrorMessage(res.message)
            }
        },
        // 获取允许的上传文件类型
        async queryFileWhitelist() {
            if (this.params.type !== 'todo') {
                return
            }
            const { code, data } = await this.$axios.post('/attachment/api/attachment/file/queryFileWhitelist')
            if (+code === 200) {
                this.typeArray = data
            }
        },
        // 是否允许上传
        isShouldUpload(res, fileTypeShow = false) {
            let flag = false
            let fileType = res.tempFiles[0].name
            const types = fileType.substring(fileType.lastIndexOf('.') + 1) // 获取文件类型
            // 图片限制
            if (fileTypeShow && !['jpg', 'jpeg', 'png', 'ico', 'bmp', 'tiff',].includes(types)) {
                this.showErrorMessage(`格式错误！请重新选择,仅支持:'jpg', 'jpeg', 'png', 'ico', 'bmp', 'tiff'格式的文件`)
                return false
            }
            if (!this.typeArray.includes(types)) {
                this.showErrorMessage("目前仅支持以下格式附件进行上传:doc,docx,xls,xlsx,ppt,pptx,pdf,ceb,txt,rar,zip,7z,jpg,jpeg,png,ico,bmp,tiff,mp3,mid,wav,flac,mp4,avi,mov,wmv`",)
                flag = false
            } else {
                flag = true
            }
            return flag
        },
        // 关闭页面
        closeCancel() {
            this.fileShow = false
        },
        dataURLtoFile(dataurl, filename) {
            let arr = dataurl.split(',');
            let mime = arr[0].match(/:(.*?);/)[1];
            let bstr = atob(arr[1]);
            let n = bstr.length;
            let u8arr = new Uint8Array(n);
            while (n--) {
                u8arr[n] = bstr.charCodeAt(n);
            }
            return new File([u8arr], filename, {
                type: mime,
            });
        }
        ,
        cameraFile() {
            if (!this.form.type) {
                this.showErrorMessage('请先选择文件类型')
                return
            }
            imp.iCamera.open(
                {
                    quality: 84, //图片质量
                    encodingType: imp.iCamera.EncodingType.JPEG, //图片格式
                },
                (successData) => {
                    let base64Top = 'data:image/jpg;base64,';
                    let file = this.dataURLtoFile(base64Top + successData.originalData, `照片${new Date().getTime()}.png`);
                    // 创建一个指向该File对象的URL
                    let fileUrl = URL.createObjectURL(file);
                    file['path'] = fileUrl
                    console.log("上传前的File", file);
                    this.uploadFileImg(file)
                },
                (err) => {
                    this.showErrorMessage('相机调用失败')
                }
            );
        },
        closeSelect(data) {
            const listResult = this.saveTypeData.filter(item => item.typeCode === data)
            this.fileShow = true
            this.form.type = listResult[0]?.typeName
            this.form.typeCode = listResult[0]?.typeCode
            this.form.fileFormatType = listResult[0]?.fileFormatType
        },
        handleChange() {
            this.$refs.initcollapse.init()
        },
    }
};
</script>
<style>
@import "@/common/uView.css";
</style>
<style scoped lang="scss">

.u-collapse-item {
    background-color: #fff;
}

.prjStage-content {
    width: calc(100% - 40rpx);
    flex-wrap: wrap;
    display: flex;
    padding: 0 20rpx;
    color: #303133;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1);
    margin: auto;
    margin-bottom: 20rpx;
    font-size: 30rpx;
    min-height: 70rpx;
    border-radius: 20rpx;
}

.conterier-page {
    background-color: #fff;
    padding-bottom: 40rpx;

    .page {
        height: 100%;

        .outside {
            width: calc(100% - 40rpx);
            flex-wrap: wrap;
            display: flex;
            padding: 0 12rpx;
            color: #303133;
            height: auto;
            justify-content: space-between;
            align-items: center;
            background-color: #efefef;
            margin: auto;
            margin-bottom: 20rpx;
            font-size: 30rpx;
            min-height: 70rpx;

            .donwond-title {
                color: #108ee9;
                width: 68%;
                word-break: break-all;
                font-size: 32rpx;
            }

            .show-icon {
                margin-right: 16rpx;
            }
        }

        .file-list {
            width: calc(100% - 40rpx);
            height: auto;
            display: flex;
            color: #000000;
            justify-content: space-between;
            align-items: center;
            background-color: #fff;
            margin: auto;
            font-size: 28rpx;
            padding: 0 12rpx;
            margin-bottom: 20rpx;
            min-height: 60rpx;
        }

        .add-color {
            background-color: #efefef;
        }
    }
}

.add-file {
    height: 74rpx;
    margin: auto;
    padding: 0 12rpx;
    border: 1px solid #ccc;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 95%;
}

.suerButton:active {
    background-color: #eee;
}
</style>